// Copyright Epic Games, Inc. All Rights Reserved.

#include "LyraUICameraManagerComponent.h"

#include "GameFramework/HUD.h"
#include "GameFramework/PlayerController.h"
#include "LyraPlayerCameraManager.h"

#include UE_INLINE_GENERATED_CPP_BY_NAME(LyraUICameraManagerComponent)

class AActor;
class FDebugDisplayInfo;

ULyraUICameraManagerComponent* ULyraUICameraManagerComponent::GetComponent(APlayerController* PC)
{
	if (PC != nullptr) // 如果玩家控制器有效
	{
		if (ALyraPlayerCameraManager* PCCamera = Cast<ALyraPlayerCameraManager>(PC->PlayerCameraManager)) // 转换为Lyra玩家相机管理器
		{
			return PCCamera->GetUICameraComponent(); // 返回UI相机组件
		}
	}

	return nullptr; // 否则返回空
}

ULyraUICameraManagerComponent::ULyraUICameraManagerComponent()
{
	bWantsInitializeComponent = true; // 设置需要初始化组件

	if (!HasAnyFlags(RF_ClassDefaultObject)) // 如果不是类默认对象
	{
		// 注册"showdebug"钩子。
		if (!IsRunningDedicatedServer()) // 如果不是专用服务器
		{
			AHUD::OnShowDebugInfo.AddUObject(this, &ThisClass::OnShowDebugInfo); // 添加显示调试信息委托
		}
	}
}

void ULyraUICameraManagerComponent::InitializeComponent()
{
	Super::InitializeComponent(); // 调用父类初始化组件
}

void ULyraUICameraManagerComponent::SetViewTarget(AActor* InViewTarget, FViewTargetTransitionParams TransitionParams)
{
	TGuardValue<bool> UpdatingViewTargetGuard(bUpdatingViewTarget, true); // 使用保护值设置更新视角目标标志

	ViewTarget = InViewTarget; // 设置视角目标
	CastChecked<ALyraPlayerCameraManager>(GetOwner())->SetViewTarget(ViewTarget, TransitionParams); // 设置相机管理器的视角目标
}

bool ULyraUICameraManagerComponent::NeedsToUpdateViewTarget() const
{
	return false; // 默认返回false
}

void ULyraUICameraManagerComponent::UpdateViewTarget(struct FTViewTarget& OutVT, float DeltaTime)
{
	// 空实现
}

void ULyraUICameraManagerComponent::OnShowDebugInfo(AHUD* HUD, UCanvas* Canvas, const FDebugDisplayInfo& DisplayInfo, float& YL, float& YPos)
{
	// 空实现
}